package com.eian.boot.rabbit.model;

import org.springframework.amqp.core.CustomExchange;

import java.util.HashMap;
import java.util.Map;

public class DelayedExchange {

    public static final String RABBITMQ_DELAYED_TYPE = "x-delayed-message";
    public static final String DELAYED_ROUTER_TYPE_KEY = "x-delayed-type";
    public static final String DEFAULT_ROUTE_TYPE = "direct";

    public static CustomExchange build(String exchange, boolean durable, boolean autoDelete) {
        Map<String, Object> args = new HashMap<>();
        args.put(DELAYED_ROUTER_TYPE_KEY, DEFAULT_ROUTE_TYPE);
        return new CustomExchange(
                exchange,
                RABBITMQ_DELAYED_TYPE,
                durable,
                autoDelete,
                args
        );
    }

    public static CustomExchange build(String exchange) {
        return build(exchange, true, false);
    }
}
